import dolphindb as ddb
from utilities.correlation_analysis import find_high_correlation_periods, process_combinations
from utilities.plot_correlation import plot_correlation
import time

start_time = time.time()
s = ddb.session("192.168.200.179", 8832, "chenzhimin", "suhhgjy98y_JHg87")

code_list = '"600866.SH",  "603739.SH",  "002481.SZ"'

start_date = "2024.02.07"
end_date = "2024.03.26"

basic_info_sql = f"""

select end_date as trading_date from tradingday_rowno(2014.01.01, 2024.06.18)
"""

for_loop_sql = """
"""
# data_sql = "select trading_date, secu_code, change_pct from stk_price where trading_date >= 2022.01.01 and secu_code in [" + code_list + "]"
data_sql =  ""
query_sql = basic_info_sql + for_loop_sql + data_sql
correlation_df = s.run(query_sql)
correlation_df['trading_date'] = correlation_df['trading_date'].dt.date
# correlation_df.to_csv("full_secu_list.csv", index=False)
correlation_df.to_csv("trading_date.csv", index=False)
# 设置时间段窗口大小
# window_size = 13

# 找出相关性较高的时间段
# correlation_df = find_high_correlation_periods(result, window_size=window_size)

# correlation_df.to_csv("DDD.csv")

# result_df = process_combinations(correlation_df)
#
# result_df.to_csv("EEE.csv")
# plot_correlation(result_df)
end_time = time.time()
execution_time = end_time - start_time
print(f"程序运行时间为：{execution_time} 秒")

